<template>
  <div>
    <div v-if="loginMode === 'remote'">
      当前 setting设置中 的登录方式为统一用户登录，请在主框架登录后返回此页面
      <ep-button type="primary" @click="handleCommonLogin">登录</ep-button>
    </div>
    <ep-form>
      <ep-form-item label="用户名">
        <ep-input v-model="form.username"></ep-input>
      </ep-form-item>
      <ep-form-item label="密码">
        <ep-input type="password" v-model="form.password"></ep-input>
      </ep-form-item>
      <ep-form-item>
        <ep-button :disabled="loginMode === 'remote'" type="primary" @click="handleLogin">登录</ep-button>
      </ep-form-item>
    </ep-form>
  </div>
</template>

<script>
import { cloneObj } from '@/utils/data'
import settings from '@/settings'
import { epEnv } from '@/common/vars'

export default {
  data() {
    return {
      loginMode: settings.loginMode,
      form: {
        username: 'epfront',
        password: 'easipass'
      }
    }
  },
  mounted() {
    if (this.$store.state.app.authorization) {
      this.$router.push('/')
    }
  },
  activated() {
    if (this.$store.state.app.authorization) {
      this.$router.push('/')
    }
  },
  methods: {
    handleLogin() {
      // 验证密码
      // bcrypt.compare(myPlaintextPassword, hash, function (err, result) {
      //   // result == true
      // })

      // this.$store
      //   .dispatch('app/login', cloneObj(this.form))
      //   .then(res => {
      //     this.loading = false
      //     this.$success('登录成功')
      //     if (this.$route.query.redirect) {
      //       this.$router.push(this.$route.query.redirect)
      //     } else {
      //       this.$router.push('/')
      //     }
      //     this.$app.$emit('close-tab', '/login')
      //   })
      //   .catch(err => {
      //     this.loading = false
      //   })
    },
    handleCommonLogin() {
      let url = epEnv.userCenter.replace('{appKey}', epEnv.appKey)
      url = url.replace('{appCode}', epEnv.appCode)
      global.open(url, '_self')
    }
  }
}
</script>

<style></style>
